package com.shenmazong.demo1907amongo.utils;

/**
 * @author 军哥
 * @version 1.0
 * @description: 接口标准化返回类定义
 * @date 2021/12/8 15:43
 */

public class ResultResponse {
    private Boolean flag;
    private Integer code;
    private String msg;
    private Object data;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Boolean getFlag() {
        return flag;
    }

    public void setFlag(Boolean flag) {
        this.flag = flag;
    }

    /**
     * @description 定义成功
     * @author 军哥
     * @date 2021/12/8 15:45
     * @version 1.0
     */
    public static ResultResponse SUCCESS() {
        ResultResponse resultResponse = new ResultResponse();
        resultResponse.setCode(200);
        resultResponse.setMsg("操作成功");
        resultResponse.setFlag(true);

        return resultResponse;
    }

    public static ResultResponse SUCCESS(Object data) {
        ResultResponse resultResponse = new ResultResponse();
        resultResponse.setCode(200);
        resultResponse.setMsg("操作成功");
        resultResponse.setData(data);
        resultResponse.setFlag(true);

        return resultResponse;
    }

    public static ResultResponse FAILED(int code) {
        ResultResponse resultResponse = new ResultResponse();
        resultResponse.setCode(code);
        resultResponse.setMsg("操作失败");
        resultResponse.setFlag(false);

        return resultResponse;
    }

    public static ResultResponse FAILED(int code, String msg) {
        ResultResponse resultResponse = new ResultResponse();
        resultResponse.setCode(code);
        resultResponse.setMsg(msg);
        resultResponse.setFlag(false);

        return resultResponse;
    }
}
